home *** CD-ROM | disk | FTP | other *** search
- VARARGS(3F) Last changed: 12-23-98
-
-
- NNAAMMEE
- vvaarraarrggss, aarrggmmnntt, ggeettaaddrr, nnuullllookk, xxeettaarrgg, rreettoouurr - allow variable
- number of arguments in argument list
-
- SSYYNNOOPPSSIISS
- ssuubbrroouuttiinnee aarrggmmnntt((_n_a_r_g_s))
- iinntteeggeerr**44 _n_a_r_g_s
-
- ssuubbrroouuttiinnee ggeettaaddrr(( _n,, _i_a_d_d_r))
- iinntteeggeerr**44 _n,, _i_a_d_d_r
-
- iinntteeggeerr**44 ffuunnccttiioonn nnuullllookk(( _n,, _i_a_d_d_r ))
- iinntteeggeerr**44 _n,, _i_a_d_d_r
-
- ssuubbrroouuttiinnee xxeettaarrgg(( _n,, _l_e_n,, _i_a_r_g))
- iinntteeggeerr**44 _n,, _l_e_n
- aannyyttyyppee _i_a_r_g
-
- ssuubbrroouuttiinnee rreettoouurr(( _n_a_r_g_s,, _l_e_n_1,, _v_a_l_1,, _l_e_n_2,, _v_a_l_2,, ......,, _l_e_n_n,, _v_a_l_n ))
- iinntteeggeerr**44 _n_a_r_g_s,, _l_e_n_1,, _l_e_n_2,, ...... _l_e_n_n
- aannyyttyyppee _v_a_l_1,, _v_a_l_2,, ...... _v_a_l_n
-
- IIMMPPLLEEMMEENNTTAATTIIOONN
- IRIX systems
-
- DDEESSCCRRIIPPTTIIOONN
- These utilities are used to provide FORTRAN 77 support for subroutines
- with variable number of arguments. In order to use these utilities,
- all variable argument subroutines must be declared in each source file
- before they are referenced or defined. This is done by adding a
- $$vvaarraarrggss compiler directive at the beginning of the source file, as
- shown by this example:
-
- $$vvaarraarrggss _v_a_s_u_b_1 _v_a_s_u_b_2 _v_a_s_u_b_3
-
- _v_a_s_u_b_1, _v_a_s_u_b_2, and _v_a_s_u_b_3 are the names of the variable argument
- subroutines which are referenced or defined in the current source
- file.
-
- aarrggmmnntt returns the number of actual arguments in the integer variable
- _n_a_r_g_s. The default behavior is to count each character argument in
- the actual argument list as two arguments because both the character
- address and its length will be put on the argument stack. The
- --cchhaarraarrgg11 option can be used to count each character argument as only
- one argument.
-
- ggeettaaddrr returns the address of the _nth argument in the variable _i_a_d_d_r.
- This function has to be used to get the length of a character argument
- because it is passed by value, not by reference, like other Fortran
- arguments.
-
- nnuullllookk returns 0 if the address of the _nth argument is the same as the
- address contained in the variable _i_a_d_d_r.
-
- xxeettaarrgg initializes _l_e_n bytes of _i_a_r_g with the value of the _nth
- argument.
-
- rreettoouurr returns values to the calling program by setting _n_a_r_g_s actual
- arguments using _l_e_n_1, _l_e_n_2, ..., _l_e_n_n bytes of the values stored in
- the variables _v_a_l_1, _v_a_l_2,..., _v_a_l_n, respectively.
-
- In normal usage of variable argument subroutines, when the formal
- argument list is specified using the maximum number of arguments the
- subroutine can receive, the argument addresses and return values are
- passed in the standard f77 convention. The only utility needed in
- this case is aarrggmmnntt to determine the number of actual arguments passed
- to the variable argument subroutine.
-
- The other utilities are needed when there is no formal argument list
- in the variable argument subroutine. xxeettaarrgg is normally used to
- initializes some local variables to the initial values of the actual
- arguments. rreettoouurr is then used to return the locally calculated
- values back to the calling subroutine by setting the actual arguments
- to the values of the local variables.
-
- EEXXAAMMPPLLEESS
- $varargs chsign
- program tvararg
- i = 1
- j = -2
- k = 3
- call chsign( i, j, k, "fourth argument", "fifth" )
- print *, i, j, k
- end
-
- subroutine chsign()
- C This subroutine changes the sign of all integer arguments passed to it
- C and prints the value of all character arguments. It assumes that
- C there are at most three integer arguments, followed by the character
- C arguments. The way this subroutine is written it has to be compiled
- C with the -chararg1 option since it assumes that the lengths of the
- C character arguments can be obtained by using GETADR(NARGS+I) where
- C NARGS is the number of arguments returned by ARGMNT().
- integer*4 val(3)
- pointer (stradr, str)
- character*(*) str
-
- call argmnt( nargs )
- print *, "Number of arguments = ", nargs
- j = min(3,nargs)
- do 10 i=1,j
- call xetarg( i, 4, val(i) )
- 10 val(i) = - val(i)
- C Get the address and the length of the character arguments
- do 100 i=j+1, nargs
- call getadr( i, stradr )
- call getadr( nargs+i-j, lenstr )
- write (*,*) str(1:lenstr)
- 100 continue
-
- call retour(j,4,val(1),4,val(2),4,val(3))
- end
-
- SSEEEE AALLSSOO
- This man page is available only online.
-